import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:freedom/const/app_content.dart';
import 'package:freedom/page/mahjong/bloc/user_state.dart';
import 'package:freedom/page/mahjong/common/mahjong_context.dart';
import 'package:freedom/page/mahjong/mahjong_game.dart';
import 'package:freedom/widget/mahjong_common.dart';

class UserInfoDialog extends StatefulWidget {
  final MahjongIndexGame game;
  const UserInfoDialog({super.key, required this.game});

  @override
  UserInfoDialogState createState() => UserInfoDialogState();
}

class UserInfoDialogState extends State<UserInfoDialog> {
  @override
  void initState() {
    super.initState();
  }

  UserState? get userInfo => widget.game.selectUser;

  @override
  Widget build(BuildContext context) {
    if (userInfo == null) {
      return const SizedBox();
    }
    return Center(
      child: Container(
        height: 200.h,
        width: 400.w,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(10),
          boxShadow: [
            BoxShadow(
              color: const Color.fromARGB(255, 19, 18, 18).withOpacity(0.5),
              spreadRadius: 5,
              blurRadius: 7,
              offset: const Offset(0, 3), // changes position of shadow
            ),
          ],
        ),
        child: Material(
            color: Colors.transparent,
            child: Column(
              children: [
                Container(
                  height: 30.h,
                  clipBehavior: Clip.hardEdge,
                  decoration: const BoxDecoration(
                    gradient: LinearGradient(
                      begin: Alignment.centerLeft,
                      end: Alignment.centerRight,
                      colors: [
                        Color.fromARGB(255, 105, 182, 245),
                        Color.fromARGB(255, 17, 142, 243)
                      ],
                    ),
                  ),
                  child: Stack(
                    fit: StackFit.expand,
                    children: [
                      Align(
                          alignment: const Alignment(-0.95, 0),
                          child: Icon(
                            Icons.person_pin,
                            size: 20.h,
                            color: Colors.white,
                          )),
                      Align(
                          alignment: const Alignment(-0.7, 0),
                          child: Text(
                            "个人信息",
                            style: TextStyle(
                                height: 1.0,
                                fontSize: 18.sp,
                                color: Colors.white,
                                fontWeight: FontWeight.w800,
                                fontFamily: AppContent.fontHyqmd),
                          )),
                      Align(
                        alignment: const Alignment(0.95, 0),
                        child: InkWell(
                          child: Icon(
                            Icons.close,
                            size: 20.h,
                            weight: 900,
                            color: Colors.white,
                          ),
                          onTap: () {
                            widget.game.setSelectUser(null);
                            MahjongContext()
                                .closeOverlay(MahjongOverlay.userInfoDialog);
                          },
                        ),
                      )
                    ],
                  ),
                ),
                Container(
                  height: 110.h,
                  decoration: BoxDecoration(
                      border: Border.all(color: Colors.grey, width: 1.0)),
                  child: Row(
                    children: [
                      Container(
                        width: 110.h,
                        height: double.infinity,
                        padding: EdgeInsets.all(25.h),
                        child: MahjongCommon.headerImage(userInfo?.portraitUrl,
                            width: double.infinity, height: double.infinity),
                      ),
                      Container(
                        height: double.infinity,
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text(
                              userInfo?.username ?? "未知",
                              style: TextStyle(
                                  height: 1.0,
                                  fontSize: 10.h,
                                  color: Colors.blue,
                                  fontWeight: FontWeight.w800,
                                  fontFamily: AppContent.fontHyqmd),
                            ),
                            SizedBox(
                              height: 5.h,
                            ),
                            Text(
                              "192.168.247.31.1",
                              style: TextStyle(
                                  height: 1.0,
                                  fontSize: 10.h,
                                  color: Colors.blue,
                                  fontWeight: FontWeight.w800,
                                  fontFamily: AppContent.fontHyqmd),
                            ),
                            SizedBox(
                              height: 5.h,
                            ),
                            Text(
                              "上海浦东新区东方明珠塔下29单元1-1",
                              style: TextStyle(
                                  height: 1.0,
                                  fontSize: 10.h,
                                  color: Colors.blue,
                                  fontWeight: FontWeight.w800,
                                  fontFamily: AppContent.fontHyqmd),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
                Expanded(
                  child: Row(
                    children: [],
                  ),
                )
              ],
            )),
      ),
    );
  }
}
